package org.lanqiao.netctoss.controller.admin;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Date;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.lanqiao.netctoss.entity.Admin;
import org.lanqiao.netctoss.service.impl.AdminServiceImpl;

/**
 * Servlet implementation class ChangeAdmin
 */
public class ChangeAdminServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ChangeAdminServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("GBK");
		HttpSession session = request.getSession();
		String user  = request.getParameter("adm_user");
		String name = request.getParameter("adm_name");
		String tel = request.getParameter("adm_tel");
		String email = request.getParameter("adm_email");
		int adm_no = Integer.parseInt(request.getParameter("adm_no"));
		PrintWriter out = response.getWriter();
		/*AdminBuss adminBuss = new AdminBussImpl();*/	
		//boolean b = adminBuss.updAdmin(new Admin(name,adm_no,tel,email));
		int i = new AdminServiceImpl().updateAdmin(new Admin(name,adm_no,tel,email));
		if(i>0){
			out.print("<script>alert('修改成功!');window.location.href='../view/index.jsp'</script>");
			Admin admin = (Admin)session.getAttribute("admin");
			admin.setAdm_tel(tel);
			admin.setAdm_name(name);
			admin.setAdm_email(email);
		}else{
			out.print("<script>alert('修改失败!');window.location.href='user/user_info.jsp'</script>");
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
